from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()


from sqlalchemy import Column,Integer,String, ForeignKey
from sqlalchemy.orm import relationship

class Girls(Base):
    __tablename__ = "girl"
    id = Column(Integer,primary_key=True)
    name = Column(String(32))

    # 创建关系
    girl2boy = relationship("Boys",secondary='hotel',backref="boy2girl")  # 对象名 关联hotel表  不是表明

class Boys(Base):
    __tablename__ = "boy"
    id = Column(Integer, primary_key=True)
    name = Column(String(32))


class Hotel(Base):
    __tablename__ = "hotel"
    id = Column(Integer, primary_key=True)
    girl_id = Column(Integer, ForeignKey("girl.id"))
    boy_id = Column(Integer, ForeignKey("boy.id"))

from sqlalchemy import create_engine
engine = create_engine("mysql+pymysql://root:root@127.0.0.1:3306/sqlalchemy?charset=utf8")
Base.metadata.create_all(engine)